import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_changeroot_demo/pages/fristPage.dart';

import '../main.dart';

class LoginPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _LoginPageState();
  }
}

class _LoginPageState extends State<LoginPage> {
  String _status = 'no-action';

  @override
  void dispose() {
    print('dispose login');
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('Login'),
      ),
      body: Container(
        child: Center(
          child: RaisedButton(
            child: Text('Login for App (${_status})'),
            onPressed: () {
              setState(() {
                _status = 'loading';
              });
              appAuth.login().then((result) {
                if (result) {
                  // Navigator.of(context).pushReplacementNamed('/frist');
                  // Navigator.of(context).pushNamedAndRemoveUntil('/frist', (Route<dynamic> route) => false);

                  // Navigator.pushAndRemoveUntil(context, CupertinoPageRoute(
                  //   builder: (context) => FristPage()
                  // ), (Route<dynamic> route) => false);

                  // Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
                  //   pageBuilder: (BuildContext context, Animation animation,
                  //   Animation secondaryAnimation) {
                  //     return FadeTransition(
                  //       //渐隐
                  //       opacity: animation,
                  //       child: FristPage(),
                  //     );
                  //   }
                  // ), (Route<dynamic> route) => false);

                  // Navigator.push(context, MaterialPageRoute(
                  //   builder: (BuildContext context) {
                  //     return FristPage();
                  //   },
                  //   fullscreenDialog: true // 这个就可以present
                  // ));

                  // (Route<dynamic> route) => false 参数如果为某一个页面，则这个页面和push之间的页面会被remove

                  Navigator.pushAndRemoveUntil(
                      context,
                      MaterialPageRoute(
                          builder: (BuildContext context) {
                            return FristPage();
                          },
                          fullscreenDialog: true // 这个就可以present
                          ),
                      (Route<dynamic> route) => false);
                } else {
                  setState(() {
                    _status = 'rejected';
                  });
                }
              });
            },
          ),
        ),
      ),
    );
  }
}
